import { useRef } from 'react';
import { Button } from '@material-ui/core'
import "./createArticle.css"
import { createArticle } from '../../api/article'
function CreateArticle(props) {
    const title = useRef(null);
    const content = useRef(null);
    const create = async () => {
        const titleValue = title.current.value, contentText = content.current.value;
        if (titleValue && contentText) {
            await createArticle({
                title: titleValue,
                content: contentText
            })
            props.history.push('./home')
        }
    }
    return <div
        className='createArtcile'
    >
        <input
            ref={title}
            placeholder='请输入标题'
            className='width-100 margin_top_20'
            style={{ height: 40 }}
        />
        <textarea
            ref={content}
            placeholder='请输入内容'
            className='width-100 margin_top_20'
            rows={10}

        />
        <Button variant="contained" className='width-100 margin_top_20' color='primary' onClick={create}>创建帖子</Button>
    </div>
}

export default CreateArticle;